package drawableClasses;

import java.awt.Graphics;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;

import util.Util;
import baseClasses.GameType;
import baseGame.Game;
import drawableClasses.components.ExitButton;
import drawableClasses.components.OptionButton;
import drawableClasses.components.PlayButton;
import drawableClasses.components.RankingButton;
import enums.GameScreenStatus;

public class MainMenu extends GameType {
	private Util u = new Util();
	
	private boolean canChangeToPlay;
	private boolean canChangeToOption;
	private boolean canChangeToRanking;
	
	private PlayButton btn_play;
	private OptionButton btn_option;
	private ExitButton btn_exit;
	private RankingButton btn_ranking;
	private ImageIcon backgroundImage;
	
	public MainMenu(){
		canChangeToOption = false;
		canChangeToPlay = false;
		canChangeToRanking = false;
		
		btn_play = new PlayButton(0, 219);
		btn_option = new OptionButton(0, 367);
		btn_ranking = new RankingButton(0, 515);
		btn_exit = new ExitButton(0, 663);
		
		setBackgroundImage(u.getImg("Files/Images/Backgrounds/bg_MainMenu.jpg"));
	}
	
	public GameScreenStatus checkCanChangeScreen(){
		GameScreenStatus result = GameScreenStatus.MainMenu;
		
		if(canChangeToPlay){
			result = GameScreenStatus.FindGame;
			canChangeToPlay = false;
		} else if(canChangeToOption){
			result = GameScreenStatus.Config;
			canChangeToOption = false;
		} else if(canChangeToRanking){
			result = GameScreenStatus.Ranking;
			canChangeToRanking = false;
		}
		
		return result;
	}
	
	public void update(MouseEvent e){
		if(btn_play.containsMouse(e.getX(), e.getY()))
			btn_play.changeToSpriteSelected();
		else
			btn_play.changeToSpriteUnselected();
		
		if(btn_option.containsMouse(e.getX(), e.getY()))
			btn_option.changeToSpriteSelected();
		else
			btn_option.changeToSpriteUnselected();
		
		if(btn_ranking.containsMouse(e.getX(), e.getY()))
			btn_ranking.changeToSpriteSelected();
		else
			btn_ranking.changeToSpriteUnselected();
		
		if(btn_exit.containsMouse(e.getX(), e.getY()))
			btn_exit.changeToSpriteSelected();
		else
			btn_exit.changeToSpriteUnselected();
	}
	
	/** Serve para ser chamado dentro do draw principal em {@link Game} */
	public void draw(Graphics bbg, Game game){
		bbg.drawImage(btn_play.getCenas()[btn_play.getCena()].getImage(), btn_play.getX(), btn_play.getY(), game);
		bbg.drawImage(btn_option.getCenas()[btn_option.getCena()].getImage(), btn_option.getX(), btn_option.getY(), game);
		bbg.drawImage(btn_ranking.getCenas()[btn_ranking.getCena()].getImage(), btn_ranking.getX(), btn_ranking.getY(), game);
		bbg.drawImage(btn_exit.getCenas()[btn_exit.getCena()].getImage(), btn_exit.getX(), btn_exit.getY(), game);
	}
	
	public void clickedAction(MouseEvent e) {
		if(btn_play.containsMouse(e.getX(), e.getY())){
			canChangeToPlay = true;
		}else if(btn_option.containsMouse(e.getX(), e.getY())){
			canChangeToOption = true;
		}else if(btn_ranking.containsMouse(e.getX(), e.getY())){
			canChangeToRanking = true;
		}else if(btn_exit.containsMouse(e.getX(), e.getY())){
			btn_exit.actionClicked(null);
		}
	}

	/**
	 * @return the btn_play
	 */
	public PlayButton getBtn_play() {
		return btn_play;
	}

	/**
	 * @param btn_play the btn_play to set
	 */
	public void setBtn_play(PlayButton btn_play) {
		this.btn_play = btn_play;
	}

	/**
	 * @return the btn_option
	 */
	public OptionButton getBtn_option() {
		return btn_option;
	}

	/**
	 * @param btn_option the btn_option to set
	 */
	public void setBtn_option(OptionButton btn_option) {
		this.btn_option = btn_option;
	}

	/**
	 * @return the btn_exit
	 */
	public ExitButton getBtn_exit() {
		return btn_exit;
	}

	/**
	 * @param btn_exit the btn_exit to set
	 */
	public void setBtn_exit(ExitButton btn_exit) {
		this.btn_exit = btn_exit;
	}

	/**
	 * @return the btn_ranking
	 */
	public RankingButton getBtn_ranking() {
		return btn_ranking;
	}

	/**
	 * @param btn_ranking the btn_ranking to set
	 */
	public void setBtn_ranking(RankingButton btn_ranking) {
		this.btn_ranking = btn_ranking;
	}

	public ImageIcon getBackgroundImage() {
		return backgroundImage;
	}

	public void setBackgroundImage(ImageIcon backgroundImage) {
		this.backgroundImage = backgroundImage;
	}

	/**
	 * @return the canChangeToPlay
	 */
	public boolean isCanChangeToPlay() {
		return canChangeToPlay;
	}

	/**
	 * @return the canChangeToOption
	 */
	public boolean isCanChangeToOption() {
		return canChangeToOption;
	}

	/**
	 * @return the canChangeToRanking
	 */
	public boolean isCanChangeToRanking() {
		return canChangeToRanking;
	}
}
